package com.example.backend.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.backend.common.Result;
import com.example.backend.entity.Admin;
import com.example.backend.entity.EntityRequest;
import com.example.backend.entity.VoteRecord;
import com.example.backend.mapper.EntityRequestMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/entity_request")
public class EntityRequestController {
    @Resource
    EntityRequestMapper entityRequestMapper;

    @PostMapping
    public Result<?> register(@RequestBody EntityRequest entityRequest){
        entityRequest.setRequestId(null);
        entityRequestMapper.insert(entityRequest);
        return Result.success();
    }

    @GetMapping("gets")
    public Result<?> gets() throws IOException {
        LambdaQueryWrapper<EntityRequest> wrapper = Wrappers.<EntityRequest>lambdaQuery().orderByAsc(EntityRequest::getRequestId);
        List<EntityRequest> res = entityRequestMapper.selectList(wrapper);
        return Result.success(res);
    }
}
